<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Xppass Administrator's Control Panel</title>
<LINK href="<?php echo $www_site_url?>/public/yav-style.css" type=text/css rel=stylesheet>
<link href="<?php echo $www_site_url?>/public/style/boxy.css" type="text/css" rel="stylesheet">
<!-- <script src="<?php echo $www_site_url?>/public/js/common.js" type="text/javascript"></script>
<script src="<?php echo $www_site_url?>/public/js/ajax.js" type="text/javascript"></script> -->
<script type="text/javascript" src="<?php echo $www_site_url?>/public/js/jquery-1.8.3.min.js"></script>
<!-- <script type="text/javascript" src="<?php echo $www_site_url?>/public/js/grid.js"></script> -->
<script type="text/javascript" src="<?php echo $www_site_url?>/public/js/jquery.boxy.js"></script>

<script>
function checkOnSubmit(formName) {
	if ($('#editbestshopper input[name="month"]').val() == '') {
		alert('月份不能为空');
		return false;
	}else if ($('#editbestshopper input[name="score"]').val() == '') {
		alert('分数不能为空');
		return false;
	}else if ($('#editbestshopper textarea[name="user_name"]').val() == '') {
		alert('用户名不能为空');
		return false;
	}
  	return true;
	/*var url = "<?php echo $www_site_url?>/admin.php";
	var params = mini.form.serialize($(formName));
	
	mini.ajax.post(url, function(r){

		var r = eval('(' + r + ')');   

		if(r.s==200){
			$('msg').innerHTML = r.m;	
		}
		if(r.s==400){
			$('msg').innerHTML = r.m;			
		}
	}, params);
	
	return false;*/
}

</script>
</head>
<body>
<div id="append"></div>
<div id="msg" style="color:red;text-align:center"></div>
	<div class="container">
		<div class="backBtn"><a href="javascript:void(0);"  id="addBestShopper">添加</a></div>
	<h3><?php echo lang('list')?></h3>
	<div class="mainbox">
		<table class="datalist fixwidth" id="bestShopperList">
			<tr>
				<th width="5%">ID</th>
				<th width="15%"><?php echo lang('month')?></th>
				<th width="60%"><?php echo lang('name')?></th>
				<th width="10%"><?php echo lang('score')?></th>
				<th width="10%"><?php echo lang('edit')?></th>
			</tr>
				<?php if(isset($bestshoppers) && is_array($bestshoppers)){
							foreach ($bestshoppers as $shopper){
					?>	
			<tr>
				<td><?php echo $shopper['ID']?></td>
				<td><strong><?php echo $shopper['for_month']?></strong></td>
				<td><?php echo $shopper['names']?></td>
				<td><strong><?php echo $shopper['score'];?></strong></td>
				<td>
					<a href="javascript:void(0);" class="editBestShopper" bshopper="<?php echo $shopper['ID']?>"><?php echo lang('edit')?></a>
					<a href="javascript:void(0);" class="deleteBestShopper" bshopper="<?php echo $shopper['ID']?>"><?php echo lang('delete')?></a>
				</td>
			</tr>
										
				<?php }
						}?>
		</table>
	</div>
	
	<!-- ADD 表单  -->
	<div id="addDiv" style="display:none;">
		<div id="addcorporationdiv">
			<form id="editbestshopper" name="editbestshopper" enctype="multipart/form-data" action="<?php echo $www_site_url?>/admin.php" method="post" onsubmit="return checkOnSubmit('editbestshopper');" >
			<input type="hidden" name="action" value="index">
			<input type="hidden" name="op" value="addbestshopper">
			<input type="hidden" name="bestId" value="">
			
			<div class="formArea">
				<div>
					<label for="month"><?php echo lang('month')?>:</label>
					<input type="text" name="month" class="textfield" value=""/>
					<span class="tips">eg:201205</span>
				</div>
				<div>
					<label for="score"><?php echo lang('score')?>:</label>
					<input type="text" name="score" class="textfield" value=""/>
					<span class="tips">10/8/6</span>
				</div>
				<div>
					<label for="user_name"><?php echo lang('username')?>:</label>
					<textarea rows="5" cols="30" name="user_name" class="textfield" ></textarea>
					<span class="tips">以英文;号分隔</span>
				</div>
				<div class="submitArea">
					<input type="submit" value="<?php echo lang('submit')?>" class="button"/>
				</div>
			</div>
			</form>
		</div>
	</div>
</div>
<script type="text/javascript">
$.fn.clearForm = function() {
	  return this.each(function() {
	    var type = this.type, tag = this.tagName.toLowerCase();
	    if (tag == 'form')
	      return $(':input',this).clearForm();
	    if (type == 'text' || type == 'hidden' || type == 'password' || tag == 'textarea')
	      this.value = '';
	    else if (type == 'checkbox' || type == 'radio')
	      this.checked = false;
	    else if (tag == 'select')
	      this.selectedIndex = -1;
	  });
};
$(document).ready(function(){
	var boxy;
	$('#addBestShopper').click(function(){
		var form = $('#editbestshopper');
		form.find('input[name="bestId"]').attr('value', '');
		form.find('input[name="month"]').attr('value', '');
		form.find('input[name="score"]').attr('value', '');
		form.find('textarea[name="user_name"]').html('');
		
		boxy = new Boxy($('#addDiv'), {title:'新增', modal: true});
		boxy.show();
		//$('#addDiv').css('display', 'block');
	});

	$('.datalist .editBestShopper').each(function(index, event){
		$(this).click(function(){
			var bshopperId = $(event).attr('bshopper');
			$.ajax({
				type: 'post',
				url: '/admin.php/index/bestshopper',
				data: {"bestId":bshopperId, "type":"getInfo"},
				success: function(r){
					r = eval('(' + r + ')');
					if (r) {
						var form = $('#editbestshopper');
						form.find('input[name="bestId"]').attr('value', r.ID);
						form.find('input[name="month"]').attr('value', r.for_month);
						form.find('input[name="score"]').attr('value', r.score);
						form.find('textarea[name="user_name"]').html(r.names);
						if (boxy){
							boxy.setTitle('编辑');
							boxy.show();
						} else {
							boxy = new Boxy($('#addDiv'), {title:'编辑', modal: true});
						}
					}
				}
			});
		});
	});

	$('.datalist .deleteBestShopper').click(function(){
		var bshopperId = $(this).attr('bshopper');
		Boxy.confirm('确认删除吗？', function(){
			$.ajax({
				type: 'post',
				url: '/admin.php/index/bestshopper',
				data: {"bestId":bshopperId, "type":"delBestShopper"},
				success: function(r) {
					r = eval('(' + r + ')');
					if (r.code == true) {
						window.location.reload(true);
					}
				}
			});
		});
		
	});
});
</script>
</body>
</html>